package han.chensing.latos.maker.swing;

import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.io.File;

public class FileSelector {
    public static final FileFilter latosFileFilter=new FileFilter() {
        @Override
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(".lat");
        }
        @Override
        public String getDescription() {
            return "Latos Project(*.lat)";
        }
    };
    public static final FileFilter midiFileFilter=new FileFilter() {
        @Override
        public boolean accept(File f) {
            return f.getName().toLowerCase().endsWith(".mid");
        }
        @Override
        public String getDescription() {
            return "Midi File(*.mid)";
        }
    };
    public static File selectFile(FileFilter fileFilter){
        JFileChooser chooser=new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.addChoosableFileFilter(fileFilter);
        int r = chooser.showDialog(null,"Open");
        if (r!=JFileChooser.APPROVE_OPTION)
            return null;
        return chooser.getSelectedFile();
    }
}
